﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Autofac;
using Autofac.Integration.Web;
using MovieDB.Data;
using MovieDB.Data.Entities;
using MovieDB.Data.Repositories;
using MovieDB.Web.Infrastructure;
using NHibernate;

namespace TestApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //var type = typeof(Program);
            //var assembly = type.Assembly;
            //string[] names = assembly.GetManifestResourceNames();
            //names = names.Where(x => x.IndexOf(".Configs.") > 0).ToArray();
            //foreach (string name in names)
            //{
            //    Console.WriteLine(name);
            //    Stream resourceStream = assembly.GetManifestResourceStream(name);
            //    StreamReader reader = new StreamReader(resourceStream);
            //    string content = reader.ReadToEnd();
            //    Console.WriteLine(content);
            //}

            var builder = new ContainerBuilder();
            Components.RegistrationComponents(builder);

            var container = builder.Build();

            //var movieRepo = container.Resolve<IRepository<Movie>>();

            //var genreRepository = container.Resolve<IRepository<Genre>>();
            //var genre = genreRepository.FindBy(x => true);

            var catRepo = container.Resolve<IRepository<Category>>();
            var cat = catRepo.FindBy(x => x.Id == 1);

            cat.Version = 1;
            catRepo.Save(cat);

            //var ratingRepo = container.Resolve<IRepository<Rating>>();
            //var rating = ratingRepo.FindBy(x => true);

            //var movie = new Movie();
            //movie.Title = "Greenzone1";
            //movie.Rating = rating;
            //movie.Category = cat;
            ////movie.CategoryId = 1;
            ////movie.RatingId = 1;

            //movie.Genres = new List<Genre>();
            //movie.Genres.Add(genre);
            //movieRepo.Save(movie);
            //genre.Movies.Add(movie);
            //genreRepository.Save(genre);

            //var uow = container.Resolve<IUnitOfWork>();
            //uow.Session.Flush();
            //uow.Rollback();

            //Console.WriteLine(movie.Id);

            container.Dispose();
            Console.ReadLine();
        }
    }
}
